package com.qingke.servlets;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

public class MyFilter implements Filter {

	@Override
	public void destroy() {
	}

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain arg2)
			throws IOException, ServletException {
		//设置字符编码
		request.setCharacterEncoding("utf-8");
		//设置字符编码
		response.setContentType("text/plain;charset=utf-8");
//		response.setCharacterEncoding("utf-8");//光写这句会报错
		System.out.println("before doFilter");
		arg2.doFilter(request, response);
		System.out.println("after doFilter");
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
		
	}

}
